package com.lingnan.controller;

import com.lingnan.dto.AdminStatisticsDTO;
import com.lingnan.entity.vo.Result;
import com.lingnan.service.AdminStatisticsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/admin/statistics")
@RequiredArgsConstructor
public class AdminStatisticsController {

    private final AdminStatisticsService adminStatisticsService;

    @GetMapping
    public Result<AdminStatisticsDTO> getAdminStatistics() {
        log.info("开始获取管理员统计信息");

        try {
            AdminStatisticsDTO statistics = adminStatisticsService.getAdminStatistics();
            log.info("成功获取管理员统计信息");
            return Result.ok(statistics);
        } catch (Exception e) {
            // 修正日志记录：使用单个占位符
            log.error("获取管理员统计信息失败: {}", e.getMessage());

            // 如果需要记录完整堆栈，使用trace级别
            if (log.isTraceEnabled()) {
                log.trace("完整错误堆栈:", e);
            }

            return Result.fail("获取统计信息时发生错误");
        }
    }
}
